package idiolect.helpers;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class Worker {
    private static Worker w = null;
    private final ExecutorService service;

    public static synchronized Worker getInstance() {
        if (w == null)
            w = new Worker();
        return w;
    }

    private Worker() {
        service = Executors.newFixedThreadPool(6);
    }

    public void addTask(Runnable r) {
        service.execute(r);
    }

    public <V> Future<V> submit(Callable<V> callable) {
        return service.submit(callable);
    }
}
